<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//用户社区账户表
class Bbs_recharge_model extends CI_Model{
    function __construct() {
        parent::__construct();
        $this->bbs_account = 'bbs_account';
        $this->bbs_recharge_order = 'bbs_recharge_order';
        $this->bbs_recharge_list = 'bbs_recharge_list';
        
        $this->bbs_award_order = 'bbs_award_order';
        $this->bbs_award_list = 'bbs_award_list';
    }
    
    function get_recharge_order($where){
        return $this->db->select('*')->from($this->bbs_recharge_order)->where($where)->get()->row_array();
    }
    function get_recharge_list($order_nid){
        return $this->db->select('*')->from($this->bbs_recharge_list)->where('order_nid',$order_nid)->get()->row_array();
    }
    
    function insert_recharge_order($data){
        $this->db->insert($this->bbs_recharge_order, $data);
        if($this->db->affected_rows()){
            return $this->db->insert_id();
        }else{
            return 0;
        }
    }
    function insert_recharge_list($data){
        $this->db->insert($this->bbs_recharge_list, $data);
        if($this->db->affected_rows()){
            return $this->db->insert_id();
        }else{
            return 0;
        }
    }
    
    function update_recharge_order($data,$order_nid){
        return $this->db->where('order_nid',$order_nid)->update($this->bbs_recharge_order, $data);
    }
    
    function update_recharge_list($data,$order_nid){
        return $this->db->where('order_nid',$order_nid)->update($this->bbs_recharge_list, $data);
    }
    
    
    //文章打赏相关
    function get_award_order($where){
        return $this->db->select('*')->from($this->bbs_award_order)->where($where)->get()->row_array();
    }
    function get_award_list($order_nid){
        return $this->db->select('*')->from($this->bbs_award_list)->where('order_nid',$order_nid)->get()->row_array();
    }
    
    function insert_award_order($data){
        $this->db->insert($this->bbs_award_order, $data);
        if($this->db->affected_rows()){
            return $this->db->insert_id();
        }else{
            return 0;
        }
    }
    function insert_award_list($data){
        $this->db->insert($this->bbs_award_list, $data);
        if($this->db->affected_rows()){
            return $this->db->insert_id();
        }else{
            return 0;
        }
    }
    
    function update_award_order($data,$order_nid){
        return $this->db->where('order_nid',$order_nid)->update($this->bbs_award_order, $data);
    }
    
    function update_award_list($data,$order_nid){
        return $this->db->where('order_nid',$order_nid)->update($this->bbs_award_list, $data);
    }
    
}
